﻿<#
#.SYNOPSIS
#    Creates the registry entries required to create Windows Explorer context 
#    menu "Open PowerShell Here" for both Directories and Drives
#.NOTES
#    Author: Keith Hill
#    Date:   Aug 9, 2009
#>

function New-OpenPowerShellContextMenuEntry
{
    param($Path)

    New-Item $Path -ItemType RegistryKey -Force
    New-ItemProperty $Path -Name '(Default)' -Value 'Open PowerShell Here'
    New-Item $Path\Command -ItemType RegistryKey
    New-ItemProperty $Path\Command -Name '(Default)' `
        -Value '"[PSPATH]" -NoExit -Command [\[]Environment[\]]::CurrentDirectory=(Set-Location -LiteralPath:''%L'' -PassThru).ProviderPath'   
}

New-OpenPowerShellContextMenuEntry 'HKCU:\Software\Classes\Directory\shell\PowerShell'
New-OpenPowerShellContextMenuEntry 'HKCU:\Software\Classes\Drive\shell\PowerShell'
                                                           